package edu.csl.study.shardingsphere.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.csl.study.shardingsphere.health.entity.User;
import edu.csl.study.shardingsphere.health.entity.User2;
import edu.csl.study.shardingsphere.health.mapper.User2Mapper;
import edu.csl.study.shardingsphere.health.mapper.UserMapper;
import edu.csl.study.shardingsphere.health.service.IUser2Service;
import edu.csl.study.shardingsphere.health.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 自动生成代码
 * @since 2022-05-19
 */
@Service
public class User2ServiceImpl extends ServiceImpl<User2Mapper, User2> implements IUser2Service {



    @Override
    public void processUsers() throws SQLException {
        insertUsers();
    }

    private List<Long> insertUsers() throws SQLException {
        List<Long> result = new ArrayList<>(10);
        for (Long i = 1L; i <= 10; i++) {
            User2 user2 = new User2();
            user2.setUserId(i);
            user2.setUserName("user_" + i);
            baseMapper.insert(user2);
            result.add(user2.getUserId());

            System.out.println("Insert User:" + user2.getUserId());

        }
        return result;
    }

    @Override
    public List<User2> getUsers() throws SQLException {
        return baseMapper.selectList(null);
    }

    @Override
    public void deleteAll() {
        baseMapper.delete(null);
    }

}
